<script>
import Toast from '@/components/index/Toast.vue'
import Choice from '@/components/index/Choice.vue'
import {
	toastRef,
	choiceRef,
	choice
} from "@/common/index/utils/toast.js"
import {
	getTrainer,
	getUserMessage
} from "@/api/index/api.js"
import {
	showToast
} from "../../common/index/utils/toast.js"
import {
	SET_STUDENT_MESSAGE,
	IS_GLASSES,
	SET_TRAINER
} from "@/common/index/config/Event.js"
import {
	AfterExperiencing,
	BeforeExperiencing,
	FormalExperiencing,
} from "@/common/index/mainManager"
import { toLogin } from "@/common/index/utils/common"
/**
 * 测试首页面
 */
export default {
	data() {
		return {
			init: false,
			logicalProcess: null
		}
	},
	async created() {
		const res = await getUserMessage()
		if (res.data.code == 200) {
			this.$store.commit(SET_STUDENT_MESSAGE, res.data.data)
			switch (res.data.data.stage) {
				case 0:
					this.logicalProcess = new BeforeExperiencing();
					break
				case 1:
					this.logicalProcess = new AfterExperiencing();
					break
				case 2:
					this.logicalProcess = new FormalExperiencing();
					break
			}

			const res2 = await getTrainer(this.$store.state.shop_id)
			if (res2.statusCode == 200) {
				this.$store.commit(SET_TRAINER, res2.data.data)
				this.logicalProcess.exec()
				this.init = true;
			} else {
				choice("请求失败", "获取工作人员信息失败", false, () => toLogin())
			}


		} else {
			showToast("", "获取用户信息失败", () => {
				uni.redirectTo({
					url: "/pages/index/index"
				})
			})
		}

	},

	onShow() {
		toastRef.value = this.$refs.toastRef
		choiceRef.value = this.$refs.choiceRef
		if (this.init) {
			this.logicalProcess.exec()
		}
	},
	onHide() { },

	mounted() {
		toastRef.value = this.$refs.toastRef
		choiceRef.value = this.$refs.choiceRef
	},
	unmounted() {

	},
	onBackPress() { },
	components: {
		Toast,
		Choice
	},
	methods: {}
}
</script>

<template>
	<view>
		<Toast ref="toastRef" />
		<Choice ref="choiceRef" />
	</view>
</template>

<style scoped>
.index-view {
	height: 100vh;
	display: flex;
	flex-direction: column;
}
</style>